package com.aring.dao;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.aring.bean.User;
import com.aring.db.DbAccess;

public class UserDao {

    public int saveUser(User user){
    	DbAccess dbAccess = new DbAccess();
    	SqlSession sqlSession = null;
    	int result = 0;
    	  try {
    		  sqlSession =	dbAccess.getSqlSession();
    		  result = sqlSession.insert("saveUser", user);
    		  sqlSession.commit();
              System.out.println(result);           
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(sqlSession!=null) sqlSession.close();
		}
        return result;
    }
	
    
     public User loginUser(User user){
    	 DbAccess dbAccess = new DbAccess();
    	 SqlSession sqlSession = null;
    	 try {
    		 sqlSession = dbAccess.getSqlSession();
    		 List<User> users = sqlSession.selectList("loginUser",user);
    		 if(users!=null && users.size()>0){
    			 user = users.get(0);
    		 }
		} catch (IOException e) {
			e.printStackTrace();
		}
    	 return user;
     }
	
}
